import {
  getrecommend,
  getarticle,
  getarticlerecommend,
  getcircleList
} from '@/api/community.js'

export default {
  // 为当前模块开启命名空间
  namespaced: true,

  // 模块的 state 数据
  state: () => ({
    // 关注列表
    articlerecommendList: [],
    myattentionList: [],
  }),

  // 模块的 mutations 方法
  mutations: {
    getStorearticlerecommend(state, articlerecommendList) {
      state.articlerecommendList = articlerecommendList
    },
    getStorearmyattention(state, myattentionList) {
      state.myattentionList = myattentionList
    }
  },

  // 模块的 getters 属性
  getters: {
    articlerecommendList: state => state.articlerecommendList,
    myattentionList: state => state.myattentionList,
  },
  actions: {
    // 获取关注的
    Getarticlerecommend({
      commit,
      state
    }) {
      getarticlerecommend().then(res => {
        // console.log(res)
		if(res.success && res.data.articleList && res.data.articleList.records){
			res.data.articleList.records.forEach(item => {
			  if(item.sliderImgs) {
			    item.sliderImgs = item.sliderImgs.split(',')
			  }
			})
		}
        // console.log(res.data.followedList)
        commit('getStorearticlerecommend', res.data.articleList.records)
        commit('getStorearmyattention', res.data.followedList)
      })
    }
  }
}
